$(document).ready(function() {
    query();
});
/*查询全部资料*/
var query = function () {
    $('#dataTable').dataTable({
        "bDeferRender": true,
        "sAjaxDataProp": "data.materialMaterialTypeTeacher",
        "sAjaxSource": "http://localhost:8080/material/queryAllMaterial",
        "sPaginationType": "bs_full", //"bs_normal", "bs_two_button", "bs_four_button", "bs_full"
        "fnPreDrawCallback": function (oSettings) {
            $('.dataTables_filter input').addClass('form-control input-large').attr('placeholder', 'Search');
            $('.dataTables_length select').addClass('form-control input-small');
        },
        "oLanguage": {
            "sSearch": "",
            "sLengthMenu": "<span>_MENU_ entries</span>"
        },
        "bJQueryUI": false,
        "bAutoWidth": false,
        "sDom": "<'row'<'col-lg-6 col-md-6 col-sm-12 text-center'l><'col-lg-6 col-md-6 col-sm-12 text-center'f>r>t<'row-'<'col-lg-6 col-md-6 col-sm-12'i><'col-lg-6 col-md-6 col-sm-12'p>>",
        "aoColumnDefs": [
            /*
            {
                "mDataProp": null,
                "sDefaultContent": "<a href='#'><span  class='label label-danger mr10 mb10' id='delete'>删除</span></a>" +
                "<a href='#'><span  class='label label-yellow mr10 mb10' id='update'>修改</span></a>",
                "aTargets": [-1]
            },
            */
            {
                "mDataProp": null,
                "sDefaultContent":"<input type ='checkbox' name='materialdown' class='icheckbox_minimal' value=''>",
                "aTargets": [0]
            }],
        "aoColumns": [
            {"mDataProp":""},
            {"mDataProp": "materialId"},
            {"mDataProp": "materialTypeName"},
            {"mDataProp": "teName"},
            {"mDataProp": "materialName"},
            {"mDataProp": "materialSize"},
            {"mDataProp": "materialUptime"},
            {"mDataProp": "materialDowntimes"},
        ],
    })
};
/*$(document).on('click', '#selectAll', function () {
    //实现全选与反选
        //$("table input[type=checkbox]").attr("checked",true)
        if ( $("table input[type=checkbox]").checked){
            $("input[name='materialdown']:checkbox").each(function(){
                $("input[name='materialdown']:checkbox").attr("checked", true);
            });
        } else {
            $("input[name='materialdown']:checkbox").each(function() {
                $("input[name='materialdown']:checkbox").attr("checked", false);
            });
        }
    });*/



$(document).on('click', '#MaterialDown', function () {
    //传一个数组到后台
    var _downMaterial_Name = [];
    $("#dataTable").find(":checkbox:checked").each(function() {
        _downMaterial_Name.push($(this).parents("tr").children().eq(4).text());
    })
   console.log(_downMaterial_Name)
    $.ajax({
        url:"http://localhost:8080/material/maretialDownload",//请求地址
        data:{"_downMaterial_Name":_downMaterial_Name},
        type: "POST",  //请求类型
        traditional: true,//加上这个属性，后台用 String[] arr 就可以接收到了
        dataType: 'blob',
        success:function () {
            window.location.herf='your_downlaod_url'
        }
    });
});



